<?php
header("Content-Type:application/json;charset=utf-8");
header('Access-Control-Allow-Origin:*');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST["uname"]) && isset($_POST["upwd"])) {
        $UNAME = $_POST["uname"];
        $UPWD = $_POST["upwd"]; $host = "127.0.0.1";
        $name = "root";
        $pwd = "";
        $db = "usermessage";
        $port = "3306";
        $conn = new mysqli($host, $name, $pwd, $db, $port);
        //3. 设置链接的字符集 php=== mysql
        mysqli_query($conn, "set names utf8");
        $sql="INSERT INTO `user2`(`uname`,`upwd`)
VALUE ('".$UNAME."','".$UPWD."');";
        $result=$conn->query($sql);
        //6.判断结果
        if ($result==1){
            $arr = array("msg" => "恭喜,注册成功", "status" => 1);
            print_r(json_encode($arr));
        }else{
            $arr = array("msg" => "注册失败", "status" => 0);
            print_r(json_encode($arr));
        }
        //7.关闭链接
        $conn->close();

    }





}else {
    $arr = array("msg" => "不支持get请求", "status" => -1);
    print_r(json_encode($arr));
}
